/**
 * @author dnk2
 */

 
 
 
 var xmlHttp ;
 
function requestScores() {
	var player = readCookie("koru_user") ;
		
	var parPlayer = newElementAtt('param', '', new Array('name', 'value'), new Array('player', player) ) ;
		
	var paramList = newElement('paramList', parPlayer);
  		 
  	var request = newElementAtt('request', paramList, new Array('lang', 'to', 'type', 'uid'), new Array('en',collection + '/GetScoreBoard', 'process', '1'  ) );
  	var message = newElement('message', request );
  	var soapMessage = messageToSOAP(message);
   
  	xmlHttp = XmlHttp.create();
  	xmlHttp.open("POST", "http://" + serverPath + "/services/localsite", true);
  	xmlHttp.onreadystatechange = new Function("processScoresResponse() ; ") ;
   
	xmlHttp.setRequestHeader("SOAPAction", "\"\"");
  	xmlHttp.setRequestHeader("Content-Type", "Content-Type: text/xml; charset=utf-8");
   
   	//logDebug("Request: " + message) ;
   
  	xmlHttp.send(soapMessage);
}



function processScoresResponse() {
	if (xmlHttp.readyState == 4) {
		logDebug("Score Response: " + xmlHttp.responseXML.xml) ;
		
		var topPlayerList = xmlHttp.responseXML.getElementsByTagName('topPlayersList')[0] ;
		var topPlayers = topPlayerList.childNodes ;
		
		var topPlayerTable = document.getElementById("topPlayers") ;
		
		for(var i=0 ; i<topPlayers.length ; i++) {
			var player = topPlayers[i] ;			
			
			var tr = topPlayerTable.insertRow(i+1) ;
			if (player.getAttribute("name") == readCookie("koru_user"))
				tr.className = "currPlayer" ;
			
			td = tr.insertCell(0) ;
			td.className = "rank" ;
			td.innerHTML = player.getAttribute("ranking") ;
			
			var td = tr.insertCell(1) ;
			td.className = "player" ;
			td.innerHTML = player.getAttribute("name") ;
			
			td = tr.insertCell(2) ;
			td.innerHTML = player.getAttribute("tasksCompleted") ;
			
			td = tr.insertCell(3) ;
			td.innerHTML = player.getAttribute("averageTaskScore") ;
			
			td = tr.insertCell(4) ;
			td.innerHTML = player.getAttribute("totalScore") ;

		}
	}	
}